package cn.zn.modules.appoin.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import cn.zn.framework.common.abs.AbsOldMainEntity;
import cn.zn.framework.common.exception.RRException;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.Query;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.appoin.dao.AppoinTimeDetailMapper;
import cn.zn.modules.appoin.entity.*;
import cn.zn.modules.appoin.entity.dto.AppointTimeDetailDTO;
import cn.zn.modules.appoin.entity.dto.AppointUserForDetailDTO;
import cn.zn.modules.appoin.entity.vo.AppoinDetailSummarySignNumVO;
import cn.zn.modules.appoin.entity.vo.AppoinWorkTimeVO;
import cn.zn.modules.appoin.entity.vo.AppoinWorkVO;
import cn.zn.modules.appoin.entity.vo.WappAppointDetailVO;
import cn.zn.modules.appoin.inter.AppoinTimeDetailInter;
import cn.zn.modules.appoin.service.*;
import cn.zn.modules.zzsys.inter.UserInter;
import cn.zn.modules.zzsys.inter.vo.SysUserVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class AppoinTimeDetailServiceImpl extends ServiceImpl<AppoinTimeDetailMapper, AppoinTimeDetail> implements AppoinTimeDetailService, AppoinTimeDetailInter {

    @Autowired
    AppoinTimeMainService appoinTimeMainService;
    @Autowired
    AppoinTimeDetailService appoinTimeDetailService;
    @Autowired
    AtRuleService atRuleService;
    @Autowired
    AtSpecialService atSpecialService;
    @Autowired
    AtSpecialWorkTimeService atSpecialWorkTimeService;
    @Autowired
    AtrSpecialService atrSpecialService;
    @Autowired
    AtrSpecialWorkTimeService atrSpecialWorkTimeService;
    @Autowired
    AppoinTimeRuleService appoinTimeRuleService;
    @Autowired
    AtrWeekService atrWeekService;
    @Autowired
    AtrWeekWorkTimeService atrWeekWorkTimeService;
    @Autowired
    AppointTimeWorkService appointTimeWorkService;
    @Autowired
    UserInter userInter;

    @Override
    public AppoinWorkVO queryAppoinWork(String mainId) {
        AppoinTimeMain appoinTimeMain = appoinTimeMainService.getById(mainId);
        AppoinTimeRuleEntity appoinTimeRuleEntityUse = appoinTimeRuleService.queryUse();
        if (appoinTimeRuleEntityUse == null) {
            throw new RRException("未开启默认规则!");
        }
        Integer detailCount = this.baseMapper.selectCount(new QueryWrapper<AppoinTimeDetail>().eq("APPOIN_TIME_MAIN_ID_", mainId));
        if (detailCount > 0) {
            throw new RRException("当前日期已经生成工作时间，不能重复生成!", HttpStatus.HTTP_BAD_REQUEST);
        }
        return this.buildAppoint(appoinTimeMain.getAppoinDate(), appoinTimeMain.getUserCode(), appoinTimeRuleEntityUse);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveGenerateTimes(String mainId) {
        // 查询待保存时间集合
        AppoinWorkVO appoinWorkVO = this.queryAppoinWork(mainId);
        if (appoinWorkVO.getAppoinWorkTimes().isEmpty()) {
            throw new RRException("未设置工作时间");
        }
        // 已经保存过时间的，进行对比
        Map<String, AppointTimeWork> appointTimeWorkMap = appointTimeWorkService.list(new QueryWrapper<AppointTimeWork>().eq("APPOIN_TIME_MAIN_ID_", mainId))
                .stream().collect(Collectors.toMap(o -> o.getStartTime().concat("-").concat(o.getEndTime()), o -> o));
        // 过滤掉已经存在的记录
        List<AppoinWorkTimeVO> appoinWorkTimeVOS = appoinWorkVO.getAppoinWorkTimes().stream().filter(o -> {
            String key = o.getStartTime().concat("-").concat(o.getEndTime());
            if (!appointTimeWorkMap.containsKey(key)) {
                return true;
            }
            appointTimeWorkMap.remove(key);
            return false;
        }).collect(Collectors.toList());
        // 构建保存数据
        List<AppointTimeWork> appointTimeWorks = appoinWorkTimeVOS.stream()
                .map(o -> {
                    AppointTimeWork appointTimeWork = new AppointTimeWork();
                    BeanUtils.copyProperties(o, appointTimeWork);
                    appointTimeWork.setAppoinTimeMainId(mainId);
                    return appointTimeWork;
                })
                .collect(Collectors.toList());
        if (!appointTimeWorks.isEmpty()) {
            appointTimeWorkService.saveBatch(appointTimeWorks);
        }
        // 需要删除的
        if (!appointTimeWorkMap.isEmpty()) {
            appointTimeWorkService.removeByIds(appointTimeWorkMap.values().stream().map(AbsOldMainEntity::getId).collect(Collectors.toList()));
        }
        AppoinTimeMain appoinTimeMain = new AppoinTimeMain();
        appoinTimeMain.setId(mainId);
        appoinTimeMain.setIsActive(true);
        appoinTimeMainService.updateById(appoinTimeMain);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveGenerateDetails(String mainId) {
        AppoinWorkVO appoinWorkVO = this.queryAppoinWork(mainId);
        List<AppoinWorkTimeVO> appoinWorkTimes = appoinWorkVO.getAppoinWorkTimes();
        if (appoinWorkTimes.isEmpty()) {
            throw new RRException("没有可生成的工作时间!");
        }

        StringBuilder workTimeBuffer = new StringBuilder();
        List<AppoinTimeDetail> details = CollUtil.newArrayList();
        // 循环递增
        Integer index = 0;
        for (AppoinWorkTimeVO appoinWorkTime : appoinWorkTimes) {
            List<AppoinTimeDetail> detailsSub = this.buildWorkTimeDetail(mainId, appoinWorkVO.getWorkDate(),
                    appoinWorkTime.getStartTime(), appoinWorkTime.getEndTime(), appoinWorkVO.getInterval(), index);
            details.addAll(detailsSub);
            workTimeBuffer.append(appoinWorkTime.getStartTime()).append("~").append(appoinWorkTime.getEndTime())
                    .append("[").append(appoinWorkVO.getInterval()).append("]").append(";");
            index += detailsSub.size();
        }
        this.saveBatch(details);
        appoinTimeMainService.update(new UpdateWrapper<AppoinTimeMain>()
                .eq("ID_", mainId).set("REMARK_", workTimeBuffer.toString()));
    }

    @Override
    public PageUtils queryByMainId(String mainId, Map<String, Object> params) {
        IPage<AppoinTimeDetail> iPage = new Query<AppoinTimeDetail>().getPage(params);
        this.baseMapper.selectPage(iPage,
                new QueryWrapper<AppoinTimeDetail>()
                        .eq("APPOIN_TIME_MAIN_ID_", mainId)
                        .orderByAsc("SORT_NUM_")
        );
        return new PageUtils(iPage);
    }

    @Override
    public PageUtils queryByMainIdForWapp(String mainId, Map<String, Object> params) {
        IPage<AppoinTimeDetail> iPage = new Query<AppoinTimeDetail>(params).getPage();
        List<AppoinTimeDetail> appoinTimeDetails = this.baseMapper.queryPage(
                null,
                null,
                null,
                null,
                null,
                null,
                mainId,
                null,
                iPage);
        if (appoinTimeDetails.size() == 0) {
            return new PageUtils(iPage);
        }
        List<WappAppointDetailVO> wappAppointDetailVOS = this.buildWappAppointDetail(appoinTimeDetails);
        PageUtils pageUtils = new PageUtils(iPage);
        pageUtils.setList(wappAppointDetailVOS);
        return pageUtils;
    }

    @Override
    public PageUtils queryByDate(Long tenantId, String date, Map<String, Object> params, Boolean isShowNoUser, boolean hiddenUser) {
        IPage<AppoinTimeDetail> iPage = new Query<AppoinTimeDetail>(params).getPage();
        // 查询工作时间明细
        List<AppoinTimeDetail> appoinTimeDetails = this.baseMapper.queryPage(
                tenantId,
                null,
                date,
                null,
                null,
                true,
                null,
                isShowNoUser,
                iPage);
        if (appoinTimeDetails.size() == 0) {
            return new PageUtils(iPage);
        }
        List<WappAppointDetailVO> wappAppointDetailVOS = this.buildWappAppointDetail(appoinTimeDetails);
        // 隐藏真实姓名
        if (hiddenUser) {
            wappAppointDetailVOS.forEach(o -> {
                if (StrUtil.isNotBlank(o.getProcessApplyCode())) {
                    o.setProcessApplyCode(StrUtil.replace(o.getProcessApplyCode(), 1, o.getProcessApplyCode().length(), '*'));
                }
            });
        }
        PageUtils pageUtils = new PageUtils(iPage);
        pageUtils.setList(wappAppointDetailVOS);
        return pageUtils;
    }

    @Override
    public PageUtils queryByUser(Long tenantId, String userId, Map<String, Object> params) {
        IPage<AppoinTimeDetail> iPage = new Query<AppoinTimeDetail>(params).getPage();
        List<AppoinTimeDetail> appoinTimeDetails = this.baseMapper.queryPage(
                tenantId,
                userId,
                null,
                null,
                null,
                true,
                null,
                null,
                iPage);
        iPage.setRecords(appoinTimeDetails);
        return new PageUtils(iPage);
    }

    @Override
    public Integer queryAvailableCountForMain(String mainId) {
        return super.count(new QueryWrapper<AppoinTimeDetail>()
                .eq("appoin_time_main_id_", mainId)
                .isNull("process_apply_code_"));
    }

    @Override
    public void saveDetail(AppointTimeDetailDTO dto, Long userId, boolean isVal) {
        AppoinTimeDetail appoinTimeDetail = new AppoinTimeDetail();
        BeanUtils.copyProperties(dto, appoinTimeDetail);
        if (userId != null) {
            appoinTimeDetail.setAppoinUserCode(userId.toString());
        }
        AppoinTimeMain appoinTimeMain = appoinTimeMainService.getById(dto.getAppoinTimeMainId());
        if (appoinTimeMain == null) {
            throw new RRException("未设置工作时间");
        }
        if (isVal) {
            // 验证是否可以预约
            Calendar[] calendars = appointTimeWorkService.isAtWork(appoinTimeMain, dto.getArriveTime());
            appoinTimeDetail.setWorkTime(calendars[0].getTime());
            // 验证是否可预约
            if (this.isExist(dto.getAppoinTimeMainId(), calendars[0].getTime(), dto.getDuration())) {
                throw new RRException("选择的时间已被其他人预约");
            }
        }
        if (StrUtil.isNotBlank(dto.getAppoinTimeDetailId())) {
            // 在此明细后插队
            AppoinTimeDetail appoinTimeDetailOld = super.getById(dto.getAppoinTimeDetailId());
            appoinTimeDetail.setWorkTime(appoinTimeDetailOld.getWorkTime());
            appoinTimeDetail.setSortNum(appoinTimeDetailOld.getSortNum());
            appoinTimeDetail.setRemark("插队");
        } else {
            // 时间处理
            String[] timeArr = dto.getArriveTime().split(":");
            if (timeArr.length != 2) {
                throw new RRException("时间格式错误");
            }
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.setTime(appoinTimeMain.getAppoinDate());
            calendar.set(Calendar.HOUR, Integer.valueOf(timeArr[0]));
            calendar.set(Calendar.MINUTE, Integer.valueOf(timeArr[1]));
            appoinTimeDetail.setWorkTime(calendar.getTime());
            AppoinTimeDetail maxSortNum = super.getOne(new QueryWrapper<AppoinTimeDetail>()
                    .eq("APPOIN_TIME_MAIN_ID_", dto.getAppoinTimeMainId())
                    .select("max(sort_num_) as sortNum"));
            appoinTimeDetail.setSortNum(maxSortNum == null ? 0 : maxSortNum.getSortNum() + 1);
        }
        super.save(appoinTimeDetail);
    }

    @Override
    public Boolean updateAppointUserForDetail(AppointUserForDetailDTO dto, Long userId, boolean isNew) {
        return super.update(
                new UpdateWrapper<AppoinTimeDetail>()
                        .eq("ID_", dto.getAppointTimeId())
                        .isNull(isNew, "PROCESS_APPLY_CODE_")
                        .set("PROCESS_APPLY_CODE_", dto.getUserName())
                        .set("appoin_mobile", dto.getUserMobile())
                        .set(userId != null, "APPOIN_USER_CODE_", userId));
    }

    @Override
    public R summarySignNum(String userCode, Long tenantId, Integer year) {
        LinkedHashMap<Object, Object> returnMap = Maps.newLinkedHashMap();
        Map<String, Long> signNumMap = this.baseMapper.summarySignNum(userCode, tenantId, year).stream().collect(Collectors.toMap(AppoinDetailSummarySignNumVO::getMonth, o -> o.getSignNum()));
        String monthStr = "";
        for (int i = 0; i < 12; i++) {
            monthStr = String.valueOf(i + 1);
            returnMap.put(monthStr.concat("月"), signNumMap.containsKey(monthStr) ? signNumMap.get(monthStr) : 0);
        }
        return R.ok().put("data", returnMap);
    }

    @Override
    public Boolean isExist(String mainId, Date selTime, Integer duration) {

        // 前一个预约是否包含了选择的时间
        Optional<AppoinTimeDetail> detailPre = super.list(new QueryWrapper<AppoinTimeDetail>()
                .eq("APPOIN_TIME_MAIN_ID_", mainId)
                .le("WORK_TIME_", selTime)
                .orderByDesc("WORK_TIME_")).stream().findFirst();
        if (detailPre.isPresent()) {
            AppoinTimeDetail appoinTimeDetail = detailPre.get();
            long between = DateUtil.between(appoinTimeDetail.getWorkTime(), selTime, DateUnit.MINUTE);
            if (between == 0L || appoinTimeDetail.getDuration() > Long.valueOf(between).intValue()) {
                return true;
            }
        }
        if (duration > 0) {
            // 后一个预约是否包含了选择的时间
            Optional<AppoinTimeDetail> detailNext = super.list(new QueryWrapper<AppoinTimeDetail>()
                    .eq("APPOIN_TIME_MAIN_ID_", mainId)
                    .gt("WORK_TIME_", selTime)
                    .orderByAsc("WORK_TIME_")).stream().findFirst();
            if (detailNext.isPresent()) {
                AppoinTimeDetail appoinTimeDetail = detailNext.get();
                long between = DateUtil.between(appoinTimeDetail.getWorkTime(), selTime, DateUnit.MINUTE);
                // 选择的时长不能大于两个工作时间的差值
                if (duration > Long.valueOf(between).intValue()) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public AppoinTimeDetail queryNearestByMainAndTime(String mainId, Date selTime) {
        Optional<AppoinTimeDetail> first = super.list(new QueryWrapper<AppoinTimeDetail>()
                .eq("APPOIN_TIME_MAIN_ID_", mainId)
                .gt("WORK_TIME_", selTime)
                .orderByAsc("WORK_TIME_")).stream().findFirst();
        return first.isPresent() ? first.get() : null;
    }

    /**
     * 得到当前可应用规则
     *
     * @param date
     * @param userCode
     * @param appoinTimeRuleEntityUse
     * @return
     */
    private AppoinWorkVO buildAppoint(Date date, String userCode, AppoinTimeRuleEntity appoinTimeRuleEntityUse) {
        // 生成工作时间规则（用户设置）
        AppoinWorkVO appoinWorkVO = this.buildUserAppoin(date, userCode);
        if (appoinWorkVO == null) {
            // 通用例外
            appoinWorkVO = this.buildCommonSpecialAppoin(appoinTimeRuleEntityUse.getId(), date);
        }
        if (appoinWorkVO == null) {
            // 通用规则
            appoinWorkVO = this.buildCommonAppoin(appoinTimeRuleEntityUse.getId(), date);
        }
        // 获取时间间隔
        if (appoinWorkVO.getInterval() == null) {
            AtRule atRule = atRuleService.getOne(new QueryWrapper<AtRule>().eq("USER_CODE_", userCode));
            if (atRule != null) {
                appoinWorkVO.setInterval(atRule.getInterval());
            } else {
                AppoinTimeRuleEntity appoinTimeRuleEntity = appoinTimeRuleService.getOne(new QueryWrapper<AppoinTimeRuleEntity>().eq("IS_ACTIVE_", true));
                appoinWorkVO.setInterval(appoinTimeRuleEntity.getInterval());
            }
        }
        appoinWorkVO.setWorkDate(date);
        return appoinWorkVO;
    }

    /**
     * 构建用户规则
     *
     * @param appoinDate
     * @param userCode
     * @return
     */
    private AppoinWorkVO buildUserAppoin(Date appoinDate, String userCode) {
        // 得到生成规则，用户规则高于通用规则
        AtSpecial atSpecial = atSpecialService.queryByUserAndDate(DateUtil.formatDate(appoinDate), userCode);
        if (atSpecial != null) {
            // 使用个人规则
            if (!atSpecial.getIsWork()) {
                throw new RRException("个人规则为非工作日");
            }
            AppoinWorkVO appoinWorkVO = new AppoinWorkVO();
            BeanUtils.copyProperties(atSpecial, appoinWorkVO);
            appoinWorkVO.setAppoinWorkTimes(atSpecial.getSpecialWorkTimes().stream().map(o -> AppoinWorkTimeVO.builder()
                    .startTime(o.getStartTime())
                    .endTime(o.getEndTime())
                    .build()).collect(Collectors.toList()));
            return appoinWorkVO;
        }
        return null;
    }

    /**
     * 通用例外
     *
     * @param appoinDate
     * @return
     */
    private AppoinWorkVO buildCommonSpecialAppoin(String ruleId, Date appoinDate) {
        AtrSpecialEntity atrSpecialEntity = atrSpecialService.queryByDate(ruleId, appoinDate);
        if (atrSpecialEntity != null) {
            // 例外设置
            List<AtrSpecialWorkTime> workTimes = atrSpecialWorkTimeService.list(new QueryWrapper<AtrSpecialWorkTime>()
                    .eq("SPECIAL_ID_", atrSpecialEntity.getId())
                    .orderByAsc("START_TIME_"));
            AppoinWorkVO appoinWorkVO = new AppoinWorkVO();
            BeanUtils.copyProperties(atrSpecialEntity, appoinWorkVO);
            appoinWorkVO.setAppoinWorkTimes(workTimes.stream().map(o -> AppoinWorkTimeVO.builder()
                    .startTime(o.getStartTime())
                    .endTime(o.getEndTime())
                    .build()).collect(Collectors.toList()));
            return appoinWorkVO;
        }
        return null;
    }

    /**
     * 通用规则
     *
     * @param appoinDate
     * @return
     */
    private AppoinWorkVO buildCommonAppoin(String ruleId, Date appoinDate) {
        // 查询统一设置的周工作时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(appoinDate);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        AtrWeekEntity atrWeekEntity = atrWeekService.queryByWeekday(ruleId, dayOfWeek);
        if (atrWeekEntity == null) {
            throw new RRException("未设置周工作规则");
        }
        if (!atrWeekEntity.getIsWork()) {
            throw new RRException("默认规则为非工作日");
        }
        List<AtrWeekWorkTimeEntity> workTimes = atrWeekWorkTimeService.list(new QueryWrapper<AtrWeekWorkTimeEntity>()
                .eq("WEEK_ID_", atrWeekEntity.getId())
                .orderByAsc("START_TIME_"));
        AppoinWorkVO appoinWorkVO = new AppoinWorkVO();
        BeanUtils.copyProperties(atrWeekEntity, appoinWorkVO);
        appoinWorkVO.setAppoinWorkTimes(workTimes.stream().map(o -> AppoinWorkTimeVO.builder()
                .startTime(o.getStartTime())
                .endTime(o.getEndTime())
                .build()).collect(Collectors.toList()));
        return appoinWorkVO;
    }

    private List<AppoinTimeDetail> buildWorkTimeDetail(String mainId, Date dateWork, String startTime, String endTime, Integer interval,
                                                       Integer index) {
        List<AppoinTimeDetail> details = CollUtil.newArrayList();
        // 每天工作开始时间
        Calendar cSetStart = Calendar.getInstance();
        cSetStart.setTime(dateWork);
        String[] startTimes = startTime.split(":");
        if (startTimes.length == 1) {
            cSetStart.set(cSetStart.get(Calendar.YEAR), cSetStart.get(Calendar.MONTH), cSetStart.get(Calendar.DATE),
                    Integer.valueOf(startTime), 0, 0);
        } else {
            cSetStart.set(cSetStart.get(Calendar.YEAR), cSetStart.get(Calendar.MONTH), cSetStart.get(Calendar.DATE),
                    Integer.valueOf(startTimes[0]), Integer.valueOf(startTimes[1]), 0);
        }
        // 每天工作结束时间
        Calendar cSetEnd = Calendar.getInstance();
        cSetEnd.setTime(dateWork);
        String[] endTimes = endTime.split(":");
        if (endTimes.length == 1) {
            cSetEnd.set(cSetEnd.get(Calendar.YEAR), cSetEnd.get(Calendar.MONTH), cSetEnd.get(Calendar.DATE),
                    Integer.valueOf(endTime), 0, 0);
        } else {
            cSetEnd.set(cSetEnd.get(Calendar.YEAR), cSetEnd.get(Calendar.MONTH), cSetEnd.get(Calendar.DATE),
                    Integer.valueOf(endTimes[0]), Integer.valueOf(endTimes[1]), 0);
        }

        Calendar cContrast = Calendar.getInstance();
        do {
            details.add(AppoinTimeDetail.builder()
                    .appoinTimeMainId(mainId)
                    .workTime(cSetStart.getTime())
                    .sortNum(index++)
                    .build());
            cSetStart.add(Calendar.MINUTE, interval);
            cContrast.setTime(cSetStart.getTime());
            cContrast.add(Calendar.MINUTE, interval);
            if (cContrast.after(cSetEnd)) {
                break;
            }
        } while (cSetStart.before(cSetEnd));
        return details;
    }

    /**
     * 得到WappAppointDetail集合
     *
     * @param appoinTimeDetails
     * @return
     */
    private List<WappAppointDetailVO> buildWappAppointDetail(List<AppoinTimeDetail> appoinTimeDetails) {
        // 查询工作人员信息
        Set<String> userCodes = CollUtil.newHashSet();
        List<WappAppointDetailVO> wappAppointDetailVOS = appoinTimeDetails.stream().map(o -> {
            if (StrUtil.isNotBlank(o.getWorkerUserCode())) {
                userCodes.add(o.getWorkerUserCode());
            }
            WappAppointDetailVO wappAppointDetailVO = new WappAppointDetailVO();
            BeanUtils.copyProperties(o, wappAppointDetailVO);
            // 计算结束时间
            if (o.getDuration() > 0) {
                Calendar endC = DateUtil.calendar(o.getWorkTime());
                endC.add(Calendar.MINUTE, o.getDuration());
                wappAppointDetailVO.setEndTime(endC.getTime());
            }
            return wappAppointDetailVO;
        }).collect(Collectors.toList());
        // 查询预约用户信息
        if (userInter != null && userCodes.size() > 0) {
            Map<String, SysUserVO> userInfoVOMap = userInter.queryByUserCodes(CollUtil.newArrayList(userCodes)).stream().collect(Collectors.toMap(
                    SysUserVO::getUsername,
                    o -> o,
                    (o1, o2) -> o1
            ));
            wappAppointDetailVOS.forEach(o -> {
                if (StrUtil.isNotBlank(o.getWorkerUserCode())) {
                    SysUserVO userInfoVO = userInfoVOMap.get(o.getWorkerUserCode());
                    o.setWorkerAvatarUrl(userInfoVO.getAvatarUrl());
                    o.setWorkerNickName(userInfoVO.getRealName());
                }
            });
        }
        return wappAppointDetailVOS;
    }

    @Override
    public void updateUserInfo(String detailId, String appoinUser, String appoinMobile) {
        AppoinTimeDetail appoinTimeDetail = AppoinTimeDetail.builder()
                .processApplyCode(appoinUser)
                .appoinMobile(appoinMobile)
                .build();
        appoinTimeDetail.setId(detailId);
        super.updateById(appoinTimeDetail);
    }
}
